# Custom Axes in R # 16 March 2013 # NJG ############################## default <- par(no.readonly=TRUE) ################################ # create random data with gamma distribution x <- 1:20 y <- rgamma(20,1,2) # set x limit to avoid clipping at start par(mar=c(5,4,4,4)) plot(x,y,type="b",pch=23,bg="slateblue", xlim=c(0,20),ylim=c(0,1.3), axes=FALSE,ann=FALSE) # use sequence and take default tick labels axis(1,at=seq(0,20,by=5)) # use mtext to add text labels in the margins mtext("Time",1,line=3) # use sequence and override with user labels axis(2, at=seq(0,1.3,length=4),labels=c("low","med","high","peak"), las=2) # thicken up tick lines and move axis out a bit axis(3,at=seq(0,20,by=5),line=1,lwd=2,lwd.ticks=2,font=2) # move the axis and ticks inward with the mgp argument axis(4,at=seq(0,1.3,length=4),labels=c("l","m","h","p"), las=2,mgp=c(0,1.4,1.9),tcl=2, col.axis="red",col="slateblue") # overplot the axis to easily create minor tick marks axis(4,at=seq(0,1.3,length=7),labels=FALSE, mgp=c(0,1.4,1.9),tcl=0.75, col="slateblue") par(default) rm(list=ls())